package com.ruoyi.network.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.network.domain.NetworkEdge;
import com.ruoyi.network.service.INetworkEdgeService;
@Component
public class NetworkEventHandler3006 implements NetworkEventHandler{
	@Autowired
	private INetworkEdgeService networkEdgeService;
	@Override
	public void invoke(JSONObject message) throws Exception {
		JSONObject param = message.getJSONObject("param");
		JSONObject command = message.getJSONObject("command");
		String terminateId = param.getString("terminateId");
		String terminateName = param.getString("terminateName");
		String terminateIp = param.getString("terminateIp");
		String innerHost = param.getString("innerHost");
		String innerPort = param.getString("innerPort");
		NetworkEdge edge = networkEdgeService.selectById(terminateId);
		boolean isInsert = false;
		if(edge == null) {
			edge = new NetworkEdge();
			edge.setId(terminateId);
			edge.setStatus("1");
			isInsert = true;
		}
		edge.setClientName(terminateName);
		edge.setClientIp(terminateIp);
		edge.setOnline(1);
//		edge.setProxyIp(innerHost);
//		edge.setProxyPort(innerPort);
		if(isInsert) {
			networkEdgeService.insert(edge);
		}else {
			networkEdgeService.update(edge);
		}
	}
	
}
